/**
 * 
 */
package registnet.courseDemand.extras;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Dexter Ryan Carrasco
 */
public class StudentChecker {
	public static void main(final String args[]) {
		final File inDB = new File(
				"C:/Documents and Settings/Dexter Ryan Carrasco/Desktop/STUDENTS_IN_DB.csv");
		final File inRec = new File(
				"C:/Documents and Settings/Dexter Ryan Carrasco/Desktop/STUDENTS_IN_REC.csv");
		final File notInDB = new File(
				"C:/Documents and Settings/Dexter Ryan Carrasco/Desktop/STUDENTS_NOT_IN_DB.csv");
		final List<String> students = new ArrayList<String>();

		try {
			// use buffering, reading one line at a time
			// FileReader always assumes default encoding is OK!
			final BufferedReader input = new BufferedReader(
					new FileReader(inDB));
			// use buffering

			try {
				String line = null; // not declared within while loop

				/*
				 * readLine is a bit quirky : it returns the content of a line
				 * MINUS the newline. it returns null only for the END of the
				 * stream. it returns an empty String if two newlines appear in
				 * a row.
				 */
				input.readLine();
				while ((line = input.readLine()) != null) {
					students.add(line);
				}
			} finally {
				input.close();

			}
		} catch (final IOException ex) {
			ex.printStackTrace();
		}

		try {
			// use buffering, reading one line at a time
			// FileReader always assumes default encoding is OK!
			final BufferedReader input = new BufferedReader(new FileReader(
					inRec));
			// use buffering

			final BufferedWriter output = new BufferedWriter(new FileWriter(
					notInDB));

			try {
				String line = null; // not declared within while loop

				/*
				 * readLine is a bit quirky : it returns the content of a line
				 * MINUS the newline. it returns null only for the END of the
				 * stream. it returns an empty String if two newlines appear in
				 * a row.
				 */
				input.readLine();
				while ((line = input.readLine()) != null) {
					if (!students.contains(line)) {
						output.write(line);
						output.newLine();
					}
				}
			} finally {
				input.close();
				output.close();
			}
		} catch (final IOException ex) {
			ex.printStackTrace();
		}

	}
}
